package fun.qu_an.minecraft.voicechatplugin.mixin;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.Mixins;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;

import static fun.qu_an.minecraft.voicechatplugin.ModsHelper.*;

@SuppressWarnings("unused")
public class Qu_anVoiceChatMixinPlugin implements IMixinConfigPlugin {
	private static final String CURRENT_PACKAGE_NAME = Qu_anVoiceChatMixinPlugin.class.getPackage().getName();
	public static final Logger LOGGER = LogManager.getLogger(Qu_anVoiceChatMixinPlugin.class.getSimpleName());

	@Override
	public void onLoad(String mixinPackage) {
		Mixins.registerErrorHandlerClass(Qu_anVoiceChatMixinErrorHandler.class.getName());
	}

	@Override
	public String getRefMapperConfig() {
		return null;
	}

	@Override
	public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
		if (!mixinClassName.startsWith(CURRENT_PACKAGE_NAME)) {
			return true;
		}
		String subMixinClassName;
		try {
			subMixinClassName = mixinClassName.substring(CURRENT_PACKAGE_NAME.length() + 1); // remove CURRENT_PACKAGE_NAME + "."
		} catch (IndexOutOfBoundsException e) {
			return true;
		}
		if (subMixinClassName.startsWith(TICK_STASIS_PACKAGE_NAME)) {
			return IS_TICK_STASIS_LOADED.get();
		}
		return true;
	}

	@Override
	public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
	}

	@Override
	public List<String> getMixins() {
		return null;
	}

	@Override
	public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
	}

	@Override
	public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
	}
}
